/*
 * IwoNew.java
 * 
 * Copyright (c) 2012 Supin P Surendran <supinps@gmail.com>.
 * 
 * This file is part of InventoryMan.
 * 
 * InventoryMan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * InventoryMan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with InventoryMan.  If not, see <http ://www.gnu.org/licenses/>.
 */

/*
 * IwoNew.java
 *
 * Created on 20 Dec, 2012, 11:17:16 AM
 */

package InventoryMan;

import java.sql.SQLException;

/**
 *
 * @author Supin P Surendran <supinps@gmail.com>
 */
public class IwoNew extends javax.swing.JInternalFrame {

    /** Creates new form IwoNew
     * @param conn Connection to the Database
     */
    @SuppressWarnings("static-access")
    public IwoNew(java.sql.Connection conn) {
        imConnection=conn;
        save=false;
        itemCodes=new java.util.HashMap<Integer, Integer>();
        indentNo=new javax.swing.DefaultComboBoxModel();
        tableIndent=new javax.swing.table.DefaultTableModel(new Object[]{"Sl No","Product","Quantity","Area","Remarks"},0);
        tableIwo=new javax.swing.table.DefaultTableModel(new Object[]{"Sl No","Product","Quantity","Area","Remarks"},0);
        initComponents();
        TblIndent.setModel(tableIndent);
        TblIwo.setModel(tableIwo);
        ac.decorate(CmbIndent);
        initIndentCombo();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        DueDate = new org.jdesktop.swingx.JXDatePicker();
        TxtIwoNo = new javax.swing.JTextField();
        IwoDate = new org.jdesktop.swingx.JXDatePicker();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        TxtDept = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        TxtDespatch = new javax.swing.JComboBox();
        CmbIndent = new org.jdesktop.swingx.JXComboBox();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TblIndent = new javax.swing.JTable();
        BnAdd = new javax.swing.JButton();
        BnFetch = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TblIwo = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        BnRemove = new javax.swing.JButton();
        BnSave = new javax.swing.JButton();
        BnCancel = new javax.swing.JButton();

        setTitle("New IWO");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon_small.png"))); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Indent No :");

        jLabel2.setText("Due Date :");

        DueDate.setDate(new java.util.Date());
        DueDate.setEditable(false);

        IwoDate.setDate(new java.util.Date());

        jLabel3.setText("IWO No :");

        jLabel4.setText("IWO Date :");

        jLabel7.setText("TO :");

        TxtDept.setText("Department");

        jLabel8.setText("Mode of Despatch :");

        TxtDespatch.setEditable(true);
        TxtDespatch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Direct", " " }));

        CmbIndent.setModel(indentNo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CmbIndent, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(DueDate, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(IwoDate, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                    .addComponent(TxtIwoNo, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(TxtDespatch, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(TxtDept, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE))
                .addContainerGap(251, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(CmbIndent, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(53, 53, 53))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(DueDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(TxtIwoNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(TxtDept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(IwoDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4)
                                .addComponent(jLabel8)
                                .addComponent(TxtDespatch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(49, Short.MAX_VALUE))
        );

        jSplitPane1.setDividerLocation(600);

        jLabel5.setText("Indent Items");

        TblIndent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(TblIndent);

        BnAdd.setText("Add >>");
        BnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnAddActionPerformed(evt);
            }
        });

        BnFetch.setText("Fetch Items");
        BnFetch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnFetchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
                    .addComponent(jLabel5)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(BnFetch, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(BnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BnAdd)
                    .addComponent(BnFetch)))
        );

        jSplitPane1.setLeftComponent(jPanel2);

        TblIwo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(TblIwo);

        jLabel6.setText("IWO Items");

        BnRemove.setText("<< Remove");
        BnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnRemoveActionPerformed(evt);
            }
        });

        BnSave.setText("Gen. IWO no.");
        BnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnSaveActionPerformed(evt);
            }
        });

        BnCancel.setText("Cancel");
        BnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addContainerGap(504, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(BnRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(BnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 234, Short.MAX_VALUE)
                        .addComponent(BnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BnRemove)
                    .addComponent(BnSave)
                    .addComponent(BnCancel)))
        );

        jSplitPane1.setRightComponent(jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1186, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BnFetchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnFetchActionPerformed
        try {
            tableIwo.getDataVector().removeAllElements();
            TblIwo.repaint();
            tableIndent.getDataVector().removeAllElements();
            TblIwo.repaint();
            stmtItems=imConnection.createStatement();
            replyItems=stmtItems.executeQuery("SELECT indent_item.sl_no,item.name,indent_item.quantity,item.code,item.width*item.length area,indent_item.remarks " +
                                              "FROM indent_item INNER JOIN item " +
                                              "WHERE indent_item.iwo=0 AND indent_item.item_code=item.code AND indent_item.indent_id="+indentNo.getSelectedItem().toString());
            while(replyItems.next()) {
                int sl=replyItems.getInt("sl_no");
                itemCodes.put(sl,replyItems.getInt("code"));
                String name=replyItems.getString("name");
                int qty=replyItems.getInt("quantity");
                int area=replyItems.getInt("area");
                String rmrks=replyItems.getString("remarks");
                tableIndent.addRow(new Object[]{sl,name,qty,area,rmrks});
            }
        }catch(java.sql.SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnFetchActionPerformed

    private void BnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnAddActionPerformed
        BnFetch.setEnabled(false);
        rowIndex=TblIndent.getSelectedRow();
        int sl=Integer.parseInt(tableIndent.getValueAt(rowIndex, 0).toString());
        String name=tableIndent.getValueAt(rowIndex, 1).toString();
        int qty=Integer.parseInt(tableIndent.getValueAt(rowIndex, 2).toString());
        int area=Integer.parseInt(tableIndent.getValueAt(rowIndex, 3).toString());
        String rmrks=tableIndent.getValueAt(rowIndex, 4).toString();
        tableIwo.addRow(new Object[]{sl,name,qty,area,rmrks});
        tableIndent.removeRow(rowIndex);
        try {
            stmtUpdate = imConnection.prepareStatement("UPDATE indent_item SET iwo=? WHERE indent_id=? and sl_no=?");
            stmtUpdate.setBoolean(1, true);
            stmtUpdate.setInt(2, Integer.parseInt(CmbIndent.getSelectedItem().toString()));
            stmtUpdate.setInt(3, sl);
            stmtUpdate.executeUpdate();
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnAddActionPerformed

    private void BnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnRemoveActionPerformed
        rowIndex=TblIwo.getSelectedRow();
        int sl=Integer.parseInt(tableIwo.getValueAt(rowIndex, 0).toString());
        String name=tableIwo.getValueAt(rowIndex, 1).toString();
        int qty=Integer.parseInt(tableIwo.getValueAt(rowIndex, 2).toString());
        int area=Integer.parseInt(tableIwo.getValueAt(rowIndex, 3).toString());
        String rmrks=tableIwo.getValueAt(rowIndex, 4).toString();
        tableIndent.addRow(new Object[]{sl,name,qty,area,rmrks});
        tableIwo.removeRow(rowIndex);
         try {
            stmtUpdate = imConnection.prepareStatement("UPDATE indent_item SET iwo=? WHERE indent_id=? and sl_no=?");
            stmtUpdate.setBoolean(1, false);
            stmtUpdate.setInt(2, Integer.parseInt(CmbIndent.getSelectedItem().toString()));
            stmtUpdate.setInt(3, sl);
            stmtUpdate.executeUpdate();
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_BnRemoveActionPerformed

    private void BnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnSaveActionPerformed
        if(tableIwo.getRowCount()>0) {
            try {
                if(!save) {
                    stmtIndent.execute("LOCK TABLES iwo_entry WRITE");
                    replyIndent=stmtIndent.executeQuery("SELECT MAX(id) FROM iwo_entry");
                    replyIndent.next();
                    newId=replyIndent.getInt("MAX(id)")+1;
                    TxtIwoNo.setText(Integer.toString(newId));
                    save=!save;
                    BnSave.setText("Save");
                }
                else {
                    //Entry
                    stmtIwo=imConnection.prepareStatement("INSERT INTO iwo_entry VALUES (?,?,?,?,?,?)");
                    stmtIwo.setInt(1, Integer.parseInt(TxtIwoNo.getText()));
                    stmtIwo.setInt(2, Integer.parseInt(CmbIndent.getSelectedItem().toString()));
                    stmtIwo.setDate(3, new java.sql.Date(IwoDate.getDate().getTime()));
                    stmtIwo.setDate(4, new java.sql.Date(DueDate.getDate().getTime()));
                    stmtIwo.setString(5, TxtDespatch.getSelectedItem().toString());
                    stmtIwo.setString(6, TxtDept.getText());
                    stmtIwo.executeUpdate();
                    stmtIwo.execute("UNLOCK TABLES");
                    //Items
                    for(int i=0;i<tableIwo.getRowCount();i++) {
                        stmtIwo=imConnection.prepareStatement("INSERT INTO iwo_item VALUES(?,?,?,?,?,?)");
                        stmtIwo.setInt(1, Integer.parseInt(TxtIwoNo.getText()));
                        stmtIwo.setInt(2, i+1);
                        stmtIwo.setInt(3, itemCodes.get(Integer.parseInt(tableIwo.getValueAt(i, 0).toString())));
                        stmtIwo.setInt(4, Integer.parseInt(tableIwo.getValueAt(i, 2).toString()));
                        stmtIwo.setString(5, TxtDept.getText());
                        stmtIwo.setBoolean(6, false);
                        stmtIwo.executeUpdate();
                    }
                    this.dispose();
                }
            }catch(java.sql.SQLException ex) {
                javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
            }
        }
        else {
            javax.swing.JOptionPane.showMessageDialog(this, "No items selected");
        }
    }//GEN-LAST:event_BnSaveActionPerformed

    private void BnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_BnCancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BnAdd;
    private javax.swing.JButton BnCancel;
    private javax.swing.JButton BnFetch;
    private javax.swing.JButton BnRemove;
    private javax.swing.JButton BnSave;
    private org.jdesktop.swingx.JXComboBox CmbIndent;
    private org.jdesktop.swingx.JXDatePicker DueDate;
    private org.jdesktop.swingx.JXDatePicker IwoDate;
    private javax.swing.JTable TblIndent;
    private javax.swing.JTable TblIwo;
    private javax.swing.JTextField TxtDept;
    private javax.swing.JComboBox TxtDespatch;
    private javax.swing.JTextField TxtIwoNo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    // End of variables declaration//GEN-END:variables

    /**
     * 
     */
    //Manually Declared Variables
    java.sql.Connection imConnection;
    java.sql.Statement stmtIndent;
    java.sql.PreparedStatement stmtUpdate;
    java.sql.PreparedStatement stmtIwo;
    java.sql.Statement stmtItems;
    java.sql.ResultSet replyItems;
    java.sql.ResultSet replyIndent;
    //DataStructures
    javax.swing.DefaultComboBoxModel indentNo;
    javax.swing.table.DefaultTableModel tableIndent;
    javax.swing.table.DefaultTableModel tableIwo;
    javax.swing.JTextField TxtIwoQty;
    int rowIndex,newId;
    java.util.Map<Integer, Integer> itemCodes;
    boolean save;
    org.jdesktop.swingx.autocomplete.AutoCompleteDecorator ac;
    //End of Declarations
    /**
     * Fetches indent table and populates
     * indent no. combobox
     */
    private void initIndentCombo() {
        try {
            stmtIndent = imConnection.createStatement();
            replyIndent = stmtIndent.executeQuery("SELECT id FROM indent_entry");
            while(replyIndent.next()) {
                indentNo.addElement(replyIndent.getInt("id"));
            }
        } catch (SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }    
}
